{{Extend "layout"}} 
{{Block "title"}}
{{- "进程值守"|T -}}
{{/Block}} 

{{Block "breadcrumb"}} 
{{Super}}
<li class="active">{{"进程值守"|T}}</li>
{{/Block}} 

{{Block "main"}}
<div class="row">
	<div class="col-md-12">
		<div class="block-flat">
			<div class="header">
				<a href="__BACKEND__/server/daemon_add" class="btn btn-success pull-right">
					<i class="fa fa-plus"></i>
					{{"添加配置"|T}}
				</a>
				<h3>{{"配置列表"|T}}</h3>
			</div>
			<div class="content">
				<div class="table-responsive">
					<table class="table no-border hover">
						<thead class="no-border">
							<tr>
								<th style="width:2%;">
									<strong>ID</strong>
								</th>
								<th>
									<strong>{{"名称"|T}}</strong>
								</th>
								<th>
									<strong>{{"命令"|T}}</strong>
								</th>
								<th>
									<strong>{{"工作目录"|T}}</strong>
								</th>
								<th style="width:15%;">
									<strong>{{"编辑时间"|T}}</strong>
								</th>
								<th style="width:80px"><strong>{{"运行状态"|T}}</strong></th>
								<th style="width:80px;">
									<strong>{{"启用状态"|T}}</strong>
								</th>
								<th style="width:15%;" class="text-center">
									<strong>{{"操作"|T}}</strong>
								</th>
							</tr>
						</thead>
						<tbody class="no-border-y">
							{{- range $k,$v := Stored.listData}}
							<tr>
								<td>{{$v.Id}}</td>
								<td>{{$v.Name}}</td>
								<td>{{$v.Command}}</td>
								<td>{{$v.Workdir}}</td>
								<td>{{if gt $v.Updated 0}}{{(Date $v.Updated).Format "2006-01-02 15:04:05"}}{{else}}{{(Date $v.Created).Format "2006-01-02 15:04:05"}}{{end}}</td>
								<td>
									{{- if eq $v.Status "running" -}}
									<span class="status-run fa fa-play text-success"> {{"运行中"|T}}</span>
									{{- else if eq $v.Status "started" -}}
									<span class="status-run fa fa-play text-primary"> {{"已启动"|T}}</span>
									{{- else if eq $v.Status "restarted" -}}
									<span class="status-run fa fa-refresh text-info"> {{"已重启"|T}}</span>
									{{- else if eq $v.Status "exited" -}}
									<span title="{{$v.Error}}" class="status-run fa fa-stop text-danger"> {{"已退出"|T}}</span>
									{{- else if eq $v.Status "killed" -}}
									<span class="status-run fa fa-stop text-danger"> {{"已终止"|T}}</span>
									{{- else if eq $v.Status "stoped" -}}
									<span class="status-run fa fa-stop text-danger"> {{"已停止"|T}}</span>
									{{- else -}}
									<span class="status-run fa fa-time text-default"> {{"空闲"|T}}</span>
									{{- end -}}
								</td>
								<td>
									<div class="checkbox checkbox-success no-margin-y">
										<input id="checkbox-{{$k}}" class="styled switch-disabled" type="checkbox" data-id="{{$v.Id}}" data-disabled="{{$v.Disabled}}"{{if eq $v.Disabled "N"}} checked="checked"{{end}} value="N" /><label for="checkbox-{{$k}}">{{"启用"|T}}</label>
									</div>
								</td>
								<td class="text-center">
									<a class="label label-default" href="__BACKEND__/server/daemon_add?copyId={{$v.Id}}" title="{{"复制"|T}}" data-toggle="tooltip"><i class="fa fa-copy"></i></a>
									<a class="label label-success" href="__BACKEND__/server/daemon_edit?id={{$v.Id}}" title="{{"编辑"|T}}" data-toggle="tooltip"><i class="fa fa-pencil"></i></a>
									<a class="label label-danger" href="__BACKEND__/server/daemon_delete?id={{$v.Id}}" onclick="return confirm('{{"真的要删除吗？"|T}}');" title="{{"删除"|T}}" data-toggle="tooltip"><i class="fa fa-times"></i></a>
								</td>
							</tr>
							{{end -}}
						</tbody>
					</table>
				</div>
				{{Stored.pagination.Render}}
			</div>
		</div>
	</div>
</div>
{{/Block}}
{{Block "footer"}}
<script>
function statusHTML(status){
	if(status=="running") return '<span class="status-run fa fa-play text-success"> {{"运行中"|T}}</span>';
	if(status=="started") return '<span class="status-run fa fa-play text-primary"> {{"已启动"|T}}</span>';
	if(status=="restarted") return '<span class="status-run fa fa-refresh text-info"> {{"已重启"|T}}</span>';
	if(status=="exited") return '<span class="status-run fa fa-stop text-danger"> {{"已退出"|T}}</span>';
	if(status=="killed") return '<span class="status-run fa fa-stop text-danger"> {{"已终止"|T}}</span>';
	if(status=="stoped") return '<span class="status-run fa fa-stop text-danger"> {{"已停止"|T}}</span>';
	return '<span class="status-run fa fa-time text-default"> {{"空闲"|T}}</span>';
}
$(function(){
	$('input.switch-disabled').on('click',function(r){
		var that=$(this),disabled=that.data('disabled')=='Y'?'N':'Y';
		$.get(BACKEND_URL+'/server/daemon_edit',{
			disabled:disabled,
			id:that.data('id')
		},function(r){
			if(r.Code==1){
				that.data('disabled',disabled);
				that.prop('checked',disabled=='N');
				that.parents('td').prev('td').html(statusHTML(r.Data));
			}
			App.message({title:'{{"系统消息"|T}}',text:r.Info,time:5000,sticky:false,class_name:r.Code==1?'success':'error'});
		},'json');
	});
});
</script>
{{/Block}}